import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
//  入口函数。返回router对象，  提供了addRoute、push等方法，
//  并且在install方法中实现了路由(main.js)，
//  注册2个全局组件router-link和router-view(app.vue)
//  2个全局变量 router、route。


const router = createRouter({
  // 浏览器历史
  history: createWebHistory(import.meta.env.BASE_URL),
  // 路由匹配规则
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue')
    },
    {
      path: '/user',
      name: 'user',
      component: () => import('../views/UserView.vue')
    },
    {
      path: '/book/:id',
      name: 'book',
      component: () => import('../views/BookView.vue')
    },

    {
      path: '/setting',
      name: 'setting',
      component: () => import('../views/UserSettingView.vue'),
      children: [
        {
          path: 'profile',
          name: 'profile',
          component: () => import('../views/Settings/UserProfilePreview.vue')
        },
        {
          path: 'editProfile',
          name: 'editProfile',
          component: () => import('../views/Settings/UserProfileEditView.vue')
        },
        {
          path: 'emails',
          name: 'emails',
          component: () => import('../views/Settings/UserEmailView.vue')
        }
        
      ]
    }
  ]
})

export default router
